package nz.ac.massey.jbuif.editor.components;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JTextArea;
import nz.ac.massey.jbuif.editor.BeanEditor;


/**
 * Class MultiLineTextEditorPanel
 * @author Daniel Haselden
 *
 */
public class MultiLineTextEditorPanel extends BaseComponent implements KeyListener {

	private static final long serialVersionUID = 1L;
	private JTextArea textField;

	/**
	 * MultiLineTextEditorPanel
	 * @param p bean editor instance
	 * @param name string name
	 * @param displayName string name to be display
	 * @param pev an object
	 */
	public MultiLineTextEditorPanel(BeanEditor p, String name,String displayName,Object pev) {
		super(p, name, displayName, pev);
		textField = new JTextArea();
		
		if(pev!=null){
			textField.setText(pev.toString());
		}
		
		textField.addKeyListener(this);
		super.addPropertyComponent(textField);	
	}	
	
	
	/**
	 * getText
	 * @return string text
	 */
	private String getText(){
		return textField.getText();
	}

	
	/**
	 * keyReleased controls the key released event
	 * @param e KeyEvent instance
	 */
	@Override
	public void keyReleased(KeyEvent e) {
		ActionEvent e1 = new ActionEvent(e.getSource(), e.getID(), "multiTextChanged");
		e1.setSource(this);
		super.setPropertyValue(this.getText());
		super.getBeanEditor().actionPerformed(e1);
	}

	
	/**
	 * keyPressed controls the key released event
	 * @param arg0 KeyEvent instance
	 */
	@Override
	public void keyPressed(KeyEvent arg0) {}
	
	
	/**
	 * keyTyped controls the key typed event
	 * @param arg0 KeyEvent instance
	 */
	@Override
	public void keyTyped(KeyEvent arg0) {}

}
